package com.smartdot.bluetoothidcarddemo.http.interceptor;

import android.content.Context;

import com.smartdot.bluetoothidcarddemo.utils.LogUtils;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by LUOLI on 2016/8/22.
 */
public class AddCookiesInterceptor implements Interceptor {
    private static final String TAG = AddCookiesInterceptor.class.getSimpleName();
    private Context context;

    public AddCookiesInterceptor(Context context) {
        super();
        this.context = context;

    }

    @Override
    public Response intercept(Chain chain) throws IOException {

        Request originalRequest = chain.request();
        Request.Builder builder = originalRequest.newBuilder();
//        LogUtils.eNormal(TAG, "token:" + LoginUtil.getToken());
//        builder.header("token", LoginUtil.getToken());

        Request.Builder requestBuilder = builder.method(originalRequest.method(), originalRequest.body());
        Request request = requestBuilder.build();
        Response originalResponse = chain.proceed(request);
        LogUtils.eNormal(TAG, "url:" + originalResponse.request().url());
        LogUtils.eNormal(TAG, "code:" + originalResponse.code());
        return originalResponse;


//        final Request.Builder builder = chain.request().newBuilder();
//        Observable.just(LoginUtil.getToken())
//                .subscribe(new Consumer<String>() {
//                    @Override
//                    public void accept(String s) throws Exception {
//                        LogUtils.eNormal(TAG,"token:"+s);
//                        builder.addHeader("token", s);
//                    }
//                });
//        return chain.proceed(builder.build());
    }
}